﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using XiDainChangAn.OA.IDAL;

namespace XiDainChangAn.OA.DALFactory
{
    /// <summary>
    /// 由简单工厂转变抽象工厂
    /// </summary>
    public class AbstractDalFactory
    {
        //数据库访问驱动层实例所在的程序集
        private static readonly string assemblyName = ConfigurationManager.AppSettings["DalAssemblyName"];           
        public static IUserInfoDal GetUserInfoDal()

        {
            //通过反射的方式来创建程序集，这就不需要创建实例了
            //从而就从“简单工厂”变化到“抽象工厂”

           
            //通过反射，加载对应程序集来创建数据库访问驱动层实例
            return Assembly.Load(assemblyName).CreateInstance(assemblyName+".UserInfoDal") as IUserInfoDal;
        }
        public static IOrderInfoDal GetOrderInfoDal()
        {
            //反射式比较慢的，我们这里做一些优化
            return Assembly.Load(assemblyName).CreateInstance(assemblyName+".OrderInfoDal") as IOrderInfoDal;

            //缓存优化  忘记了
            //HttpRuntime.Cache.Get("");
        }

        public static IWF_InstanceDal GetWF_InstanceDal()
        {
            //反射式比较慢的，我们这里做一些优化
            return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".WF_InstanceDal") as IWF_InstanceDal;
        }

        public static IWF_TempDal GetWF_TempDal()
        {
            return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".WF_TempDal") as IWF_TempDal;
        }

        public static IWF_StepDal GetWF_SetpDal()
        {
            return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".WF_StepDal") as IWF_StepDal;
        }

        public static IFileInfoDal GetFileInfDal()
        {
            return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".FileInfoDal") as IFileInfoDal;
        }

        public static IRoleInfoDal GetRoleInfoDal()
        {
            return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".RoleInfoDal") as IRoleInfoDal;
        }

        public static IActionInfoDal GetActionInfoDal()
        {
            return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".ActionInfoDal") as IActionInfoDal;
        }
    }
}
